package com.woniuxy.closer.controller;


import com.woniuxy.closer.ResponseEntity;
import com.woniuxy.closer.entity.ContactsV;
import com.woniuxy.closer.entity.VaccinationRecords;
import com.woniuxy.closer.service.ContactsService;
import com.woniuxy.closer.service.VaccinationRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李玉桃
 * @since 2022-07-20
 */
@RestController
@RequestMapping("/closer/vaccination-records")
public class VaccinationRecordsController {


    @Autowired
    VaccinationRecordsService VaccinationRecordsService;

    @GetMapping("{id}")
    public ResponseEntity findById(@PathVariable int id){
        return new ResponseEntity(VaccinationRecordsService.getById(id));
    }

    @PostMapping("")
    public ResponseEntity save(@RequestBody VaccinationRecords vaccinationRecords){
        boolean flag = VaccinationRecordsService.save(vaccinationRecords);
        if(flag){
            return ResponseEntity.SUCCESS;
        }else{
            return ResponseEntity.ERROR;
        }
    }

    @DeleteMapping("")
    public ResponseEntity delete(@PathVariable int id){
        boolean flag = VaccinationRecordsService.removeById(id);
        if(flag){
            return ResponseEntity.SUCCESS;
        }else{
            return ResponseEntity.ERROR;
        }
}

    @PostMapping("find")
    public ResponseEntity findByCondition(@RequestBody Map map){
        for (Object o : map.keySet()) {
            if(map.get(o.toString()) .equals("")){
                map.remove(o.toString());
            }
        }
        System.out.println(map);
        return new ResponseEntity(VaccinationRecordsService.listByMap(map));
    }




}

